package com.itheima.pinda.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.ScheduleJobLogDTO;
import com.itheima.pinda.entity.ScheduleJobLogEntity;
import com.itheima.pinda.mapper.ScheduleJobLogMapper;
import com.itheima.pinda.service.ScheduleJobLogService;
import com.itheima.pinda.utils.ConvertUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author llhuang10
 * @date 2021/10/25 11:13
 */
@Service
public class ScheduleJobLogServiceImpl extends ServiceImpl<ScheduleJobLogMapper, ScheduleJobLogEntity> implements ScheduleJobLogService {


    @Override
    public IPage<ScheduleJobLogEntity> page(Map<String, Object> params) {
        IPage<ScheduleJobLogEntity> page = new Page<>();
        page.setCurrent(Long.parseLong(params.getOrDefault("page", 1).toString()));
        page.setSize(Long.parseLong(params.getOrDefault("pageSize", 10).toString()));

        return super.page(page, Wrappers.<ScheduleJobLogEntity>lambdaQuery()
                .eq(params.containsKey("jobId"), ScheduleJobLogEntity::getJobId, params.get("jobId"))
                .orderByAsc(ScheduleJobLogEntity::getCreateDate));
    }

    @Override
    public ScheduleJobLogDTO get(Long id) {
        ScheduleJobLogEntity entity = super.getById(id);
        return ConvertUtils.sourceToTarget(entity, ScheduleJobLogDTO.class);
    }
}
